﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MengLin.OOP.DesignPattern.CompsitePattern.RoleReward
{
    /// <summary>
    /// 具体的角色
    /// </summary>
    public class Role : AbstractRole
    {
        private List<AbstractRole> roleChildList = new List<AbstractRole>();

        /// <summary>
        /// 计算分红
        /// </summary>
        /// <param name="total"></param>
        public override void CalculateDividend(double totalMoney)
        {
            double result = totalMoney * (Percent / 100);
            Console.WriteLine("{0} 分红 {1}", Name, result);
            foreach (var domainChild in roleChildList)
            {
                domainChild.CalculateDividend(result);
            }
        }

        /// <summary>
        /// 增加子节点
        /// </summary>
        /// <param name="roleChild"></param>
        public override void AddChild(AbstractRole roleChild)
        {
            roleChildList.Add(roleChild);
        }
    }
}
